package com.medusa.aps.business.modules.modeling.model.input;

import cn.hutool.core.util.IdUtil;
import com.medusa.aps.business.model.enums.ProductionType;
import com.medusa.aps.business.modules.modeling.mp.entity.BomItem;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.List;

/**
 * BOM子项物料
 *
 * @author miskw
 * @date 2023/8/22
 */
@Data
@Accessors(chain = true)
public class BomItemTransfersDTO {
    @Schema(description = "序号")
    private Long no;
    @Schema(description = "层级")
    @NotNull(message = "层级不能为空")
    private Integer level;
    @Schema(description = "父项物料编码")
    private String parentMaterialCode;
    @Schema(description = "物料id")
    @NotNull(message = "物料id不能为空")
    private Long materialId;
    @Schema(description = "物料编码")
    @NotNull(message = "物料编码不能为空")
    private String materialCode;
    @Schema(description = "物料名称")
    @NotNull(message = "物料名称不能为空")
    private String materialName;
    @Schema(description = "物料规格")
    private String materialSpecification;
    @Schema(description = "生产类型")
    private ProductionType productionType;
    @Schema(description = "单位")
    @NotNull(message = "单位不能为空")
    private String unit;
    @Schema(description = "单件用量")
    @NotNull(message = "单件用量不能为空")
    private BigDecimal unitUsage;
    @Schema(description = "备注")
    private String remarks;
    @Valid
    @Schema(description = "子项物料")
    private List<BomItemTransfersDTO> children;

    public BomItem toBeanBomItem(String bomCode, Long id) {
        return new BomItem()
                .setId(id == null ? IdUtil.getSnowflakeNextId() : id)
                .setLevel(level)
                .setBomCode(bomCode)
                .setMaterialId(materialId)
                .setMaterialCode(materialCode)
                .setMaterialName(materialName)
                .setUnit(unit)
                .setUnitUsage(unitUsage)
                .setMaterialSpecification(materialSpecification)
                .setProductionType(productionType)
                .setRemarks(remarks);
    }
}
